# 文件的操作
# 换行功能需要转义字符\n实现
fileWriter = open('name.txt', 'w', encoding='utf-8')
fileWriter.write('诸葛亮' + '\n')
fileWriter.close()

fileAppend = open('name.txt', 'a', encoding='utf-8')
fileAppend.write('刘备' + '\n')
# 批量写入
fileAppend.writelines(['关羽\n', '张飞'])
fileAppend.close()

# 读取文件
fileReader = open('name.txt', encoding='utf-8')
print(fileReader.read())
fileReader.close()

fileReaderLine = open('name.txt', encoding='utf-8')
# 批量按行读取
for line in fileReaderLine.readlines():
    print('========\n' + line)
fileReaderLine.close()

filePointer = open('name.txt', encoding='utf-8')
# 读取操作指针位置0
print('当前文件指针位置：', filePointer.tell())
# 指针移动一个位置1
print('读取一个字符，字符内容：', filePointer.read(1))
print('当前文件指针位置：', filePointer.tell())
# 指针重置起始位置0
print('指针重置起始位置0：', filePointer.seek(0))

filePointer.close()
